/* 
 * Copyright (c)	Insighten Intelligent Equipment co.,LTD
 * 
 *  Use of this software is controlled by the terms and conditions found
 *  in the license agreement under which this software has been supplied.
 * 
 */
/** 
 * @file udp_thread.c
 * @brief udp thread for client
 * @author taco [tacoee@gmail.com]
 * @version 0.1
 * @date 2010-09-11
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

#include "udp_thread.h"
#include "udp_lib.h"
#include "types.h"
#include "main.h"

struct _UdpCliEnv {
	UdpSocket *udp_cli;
	char *lckaddr;
	char *remaddr;
	pthread_mutex_t	mutex;
	pthread_cond_t	cond;
};

UdpCliEnv *udp_cli_env_new()
{
	UdpCliEnv *thiz = NULL;

	thiz = calloc(sizeof(UdpCliEnv), 1);

	return thiz;
}

Ret udp_svr_env_init(UdpCliEnv *thiz, UdpSocket *udp_cli)
{
	return_val_if_fail(thiz != NULL && udp_cli != NULL, RET_FAIL);

	thiz->udp_cli = udp_cli;

	if (pthread_mutex_init(&thiz->mutex, NULL) != 0) {
		return RET_FAIL;
	}
	if (pthread_cond_init(&thiz->cond, NULL) != 0) {
		return RET_FAIL;
	}

}

Ret udp_svr_cli_destroy(UdpCliEnv *thiz)
{
	if (thiz != NULL) {
		pthread_mutex_destroy(&thiz->mutex);
		pthread_cond_destroy(&thiz->cond);
		free(thiz);
	}
	
	return RET_OK;
}

Ret udp_cli_env_set_lckaddr(UdpCliEnv *thiz, char *lckaddr)
{
	return_val_if_fail(thiz != NULL && lckaddr != NULL, RET_FAIL) {
		thiz->lckaddr = lckaddr;
	}

	return RET_OK;
}


void *udp_cli_thread(void *arg)
{
	UdpCliEnv *evn = (UdpCliEnv *)arg;
	UdpSocket *udp_svr = (UdpSocket *)evn->udp_cli;

	while(!get_quit()) {
		dbg_log("created udp process thread.");
	}

	return THREAD_FAIL;
}
